package com.example.bilibiliprojectspringboot.result;

import com.example.bilibiliprojectspringboot.enumeration.HttpStatusEnum;
import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {
  private Integer code;
  private String message;
  private String status;
  private T data;

  public static <T> Result<T> success() {
    Result<T> result = new Result<>();
    result.code = HttpStatusEnum.OK.getCode();
    result.message = "请求成功";
    result.status = "success";
    return result;
  }

  public static <T> Result<T> success(T object) {
    Result<T> result = new Result<>();
    result.data = object;
    result.code = HttpStatusEnum.OK.getCode();
    result.message = "请求成功";
    result.status = "success";
    return result;
  }

  public static <T> Result<T> error(HttpStatusEnum code, String message) {
    Result<T> result = new Result<>();
    result.code = code.getCode();
    result.message = message;
    result.status = "error";
    return result;
  }


}
